//
//  YKSelectIllnessController.m
//  HMPersonalDoctor
//
//  Created by 叶文凯 on 16/9/9.
//  Copyright © 2016年 geduo. All rights reserved.
//

#import "YKSelectIllnessController.h"
#import "YKIllness.h"

static NSString *cellID = @"CELL";
@interface YKSelectIllnessController ()

@end

@implementation YKSelectIllnessController
{
    NSArray <YKIllness *>*_illList;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self loadData];
    [self setupUI];
}


- (void)setupUI
{
    self.navigationItem.title = self.name;
    
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:cellID];

}
- (void)loadData
{
//    \U0000fffc\n\n男科
    NSString *fileName;
    if (self.tag == 3) {

     fileName = @"illness3";
        
    }else
    {
        fileName = self.name;
    }
    NSString *filePath = [[NSBundle mainBundle] pathForResource:fileName ofType:@"plist"];
    
    NSArray *arr = [NSArray arrayWithContentsOfFile:filePath];
    
    NSMutableArray *tempArrM = [NSMutableArray arrayWithCapacity:arr.count];
    [arr enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        
        YKIllness *model = [YKIllness illnessModelWithDict:obj];
        
        [tempArrM addObject:model];

    }];
    _illList = tempArrM.copy;
        

}

- (void)setName:(NSString *)name
{
    _name = name;

}
- (void)setTag:(NSInteger)tag
{
    _tag = tag;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return _illList.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID forIndexPath:indexPath];
    YKIllness *model = _illList[indexPath.row];
    
    if (self.tag == 3) {
        cell.textLabel.text = model.name;
        
        return cell;
    }
    cell.textLabel.text = model.ci3_name;
    
    return cell;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    YKIllness *model = _illList[indexPath.row];
    
    if (self.tag == 3) {
        
        NSString *style = model.name;
        if (self.styleBlock) {

            self.styleBlock(style);
        }
        
    }
    else
    {
    NSString *name = model.ci3_name;
    if (self.nameBlock) {
        
        self.nameBlock(name);
        
    }
    }
    [self.navigationController popViewControllerAnimated:YES];
    
}

@end
